package com.seu.me.thirdpart.sms;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;


public class SendSMS {
    public static String username = "500021";
    public static String password = "hgsah25";
    public static String phoneid = "15214353028";
    //原地址(扩展码 可不填 前端获取 测试时为方便定义)
    public static String source_address = "扩展码";
    //外部编码
    public static long external_id = 0x1L;
    //发送短信方法
    public static String mt = "mt";

    public static void main(String[] args) {
        sengSindleSMS();
    }

    //单一内容下发&单一内容群发
    public static void sengSindleSMS() {
        String result = "";
        String content = "【暖心口袋】验证码：654321，请在5分钟内完成验证。";
        try {
            //做URLEncoder - UTF-8编码
            String sm = URLEncoder.encode(content, "utf8");
            //将参数进行封装
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("un", username);
            paramMap.put("pw", password);

            //单一内容时群发  将手机号用;隔开
            paramMap.put("da", phoneid);
            paramMap.put("sm", sm);
            //发送POST请求
            result = HttpClient.SendPOST(mt, paramMap);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("发送结果：" + result);
    }

    //不同内容不同号码群发
    public static void sendGroupSMS() {
        //不同内容不同号码群发  将手机号与下发内容分编写为：手机号#外部编码#短信内容|手机号#外部编码#短信内容。格式
        String[] mobiles = {"手机号", "手机号"};
        String[] contents = {"【测试】这是一条测试短信aaa123", "【测试】这是一条测试短信aaa123"};
        StringBuffer data = new StringBuffer();
        for (int i = 1; i <= mobiles.length; i++) {
            String mobile = mobiles[i - 1];
            if (i > 0 && i != mobiles.length && mobiles.length != 1) {
                data.append(mobile + "#" + contents[i - 1] + "|");
            } else if (i == mobiles.length) {
                data.append(mobile + "#" + contents[i - 1]);
            }
        }
        String content = data.toString();


        String result = "";
        try {
            //做URLEncoder - UTF-8编码
            String sm = URLEncoder.encode(content, "utf8");
            //将参数进行封装
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("un", username);
            paramMap.put("pw", password);
            paramMap.put("da", "");
            paramMap.put("sm", sm);
            result = HttpClient.SendPOST(mt, paramMap);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(result);
    }
}
